package com.osgi.desktop.ui.plugins;

import com.osgi.desktop.domain.SitePlugin;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;

public class InstalarPluginsListener implements MouseListener {
    private SitePluginSelectionListener sitePluginSelectionListener;
    public InstalarPluginsListener(SitePluginSelectionListener sitePluginSelectionListener){
        this.sitePluginSelectionListener = sitePluginSelectionListener;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        JXTreeTable table = (JXTreeTable)e.getSource();
        int selectedRow = table.getSelectedRow();
        if (selectedRow > -1) {
            DefaultMutableTreeTableNode nodeSelecionado = (DefaultMutableTreeTableNode)table.getTreeSelectionModel().getSelectionPath().getLastPathComponent();
            Object object = nodeSelecionado.getUserObject();
            if (object instanceof SitePlugin) sitePluginSelectionListener.notifySitePluginSelected((SitePlugin)object);
            else sitePluginSelectionListener.notifySitePluginSelected(null);
        }
    }
    @Override
    public void mousePressed(MouseEvent e) {}
    @Override
    public void mouseReleased(MouseEvent e) {}
    @Override
    public void mouseEntered(MouseEvent e) {}
    @Override
    public void mouseExited(MouseEvent e) {}
}
